package cs2114.gCalc;

// -------------------------------------------------------------------------
/**
 * Create a class to do the calculations for the app
 *
 * @author Richie Steinwand (richie4)
 * @version 05.05.12
 */

public class Calculate
{


    private String course;
    private int grade;
    private String letterGrade;



    // ----------------------------------------------------------
    /**
     * Create a constructor for the class
     */
    public Calculate()
    {
        myAssignmentGradesArray = new Double[10];
        myCoursesArray = new String[10];
        myCourseGradesArray = new Double[10];
        myCreditsArray = new Integer[10];
    }


    // ----------------------------------------------------------
    /**
     * create a method to determine the value of an assignment
     *
     * @param course
     * @param weight
     * @param score
     * @param possible
     * @return valueOfAssignment is the value of the assignment
     */
    public double weightedAssignment(
        String course,
        int weight,
        int score,
        int possible)
    {
        double percentage = score / possible;
        double valueOfAssignment = percentage * (weight / 100);
        myAssignmentGradesArray[0] = valueOfAssignment;
        return valueOfAssignment;

    }


    // ----------------------------------------------------------
    /**
     * create a method to determine the final letter grade in a class
     *
     * @param course
     * @return letterGrade is the course grade in letter form
     */
    public String finalLetterGrade(String course)
    {
        double sumTotal = 0;
        String letterGrade = null;
        for (int i = 0; i <= myAssignmentGradesArray.length; i++)
        {
            sumTotal = sumTotal + myAssignmentGradesArray[i];
            letterGrade = letterGrade(sumTotal);
        }

        return letterGrade;
    }


    // ----------------------------------------------------------
    /**
     * create a method to calculate the final number grade
     *
     * @param course
     * @return sumTotal is the sum of all the assignment grades
     */
    public double finalNumberGrade(String course)
    {
        double sumTotal = 0;
        for (int i = 0; i <= myAssignmentGradesArray.length; i++)
        {
            sumTotal = sumTotal + myAssignmentGradesArray[i];
            myCourseGradesArray[0] = sumTotal;

        }
        return sumTotal;
    }


    // ----------------------------------------------------------
    /**
     * create a method to determine the current (numerical) grade in a class
     *
     * @param course
     * @return sumTotal is the sum of the assignment grades so far
     */
    public double currentCourseGrade(String course)
    {
        double sumTotal = 0;
        for (int i = 0; i <= myAssignmentGradesArray.length; i++)
        {
            sumTotal = sumTotal + myAssignmentGradesArray[i];

        }
        return sumTotal;
    }


    // ----------------------------------------------------------
    /**
     * create a method to calculate what you need on the final assignment to get
     * the grade that you want in the class
     *
     * @param course
     * @param worthOfLastAssignment
     * @param desiredPercentage
     * @return necessary is the score that you need
     */
    public double desiredScore(
        String course,
        double worthOfLastAssignment,
        double desiredPercentage)
    {
        double value = worthOfLastAssignment / 100;

        double currentPercentage = currentCourseGrade(course);

        double necessary = (desiredPercentage - currentPercentage) * value;

        return necessary;
    }


    // ----------------------------------------------------------
    /**
     * create a method to turn a numerical grade into a letter grade
     *
     * @param score
     * @return the letter of the grade
     */
    public String letterGrade(double score)
    {
        if (93 <= score)
        {
            return "A";
        }

        else if (89.5 <= score && score < 93)
        {
            return "A-";
        }
        else if (87 <= score && score < 89.5)
        {
            return "B+";
        }
        else if (83 <= score && score < 87)
        {
            return "B";
        }
        else if (79.5 <= score && score < 83)
        {
            return "B-";
        }
        else if (77 <= score && score < 79.5)
        {
            return "C+";
        }
        else if (73 <= score && score < 77)
        {
            return "C";
        }
        else if (69.5 <= score && score < 73)
        {
            return "C-";
        }
        else if (67 <= score && score < 69.5)
        {
            return "D+";
        }
        else if (63 <= score && score < 67)
        {
            return "D";
        }
        else if (59.5 <= score && score < 63)
        {
            return "D-";
        }
        else
        {
            return "F";
        }

    }


    // ----------------------------------------------------------
    /**
     * create a method to convert a numerical grade into a gpa
     *
     * @param score
     * @return the grade on a 4.0 scale
     */
    public String numericalGrade(double score)
    {
        if (93 <= score)
        {
            return "4.0";
        }

        else if (89.5 <= score && score < 93)
        {
            return "3.7";
        }
        else if (87 <= score && score < 89.5)
        {
            return "3.3";
        }
        else if (83 <= score && score < 87)
        {
            return "3.0";
        }
        else if (79.5 <= score && score < 83)
        {
            return "2.7";
        }
        else if (77 <= score && score < 79.5)
        {
            return "2.3";
        }
        else if (73 <= score && score < 77)
        {
            return "2.0";
        }
        else if (69.5 <= score && score < 73)
        {
            return "1.7";
        }
        else if (67 <= score && score < 69.5)
        {
            return "1.3";
        }
        else if (63 <= score && score < 67)
        {
            return "1.0";
        }
        else if (59.5 <= score && score < 63)
        {
            return "0.7";
        }
        else
        {
            return "0";
        }

    }


    // ----------------------------------------------------------
    /**
     * create a method to calculate the semester gpa
     *
     * @return GPA is the semester GPA
     */
    public double calculateSemesterGPA()
    {
        double creditValue = 0;
        for (int i = 0; i <= myCourseGradesArray.length; i = i + 2)
        {
            creditValue =
                creditValue + (myCourseGradesArray[i] * myCreditsArray[i + 1]);
        }
        int totalCredits = 0;
        for (int i = 0; i <= myCoursesArray.length; i++)
        {
            totalCredits = totalCredits + myCreditsArray[i + 1];
        }
        double GPA = creditValue / totalCredits;
        return GPA;

    }
}
